package com.nari.ies.ne.nw.server.service.fileScore.impl;

import com.nari.ies.ne.nw.server.entity.PvFileScoreEntity;
import com.nari.ies.ne.nw.server.entity.WindFileScoreEntity;
import com.nari.ies.ne.nw.server.mapper.FileScoreMapper;
import com.nari.ies.ne.nw.server.service.fileScore.ICDQYCFileScoreService;
import com.nari.ies.ne.nw.server.service.fileScore.IFileScoreService;
import com.nari.ies.ne.nw.server.util.DataUtil;
import com.nari.ies.ne.nw.server.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class CDQYCFileScoreServiceImpl implements ICDQYCFileScoreService {
    @Autowired
    private IFileScoreService fileScoreService;
    @Autowired
    private FileScoreMapper fileScoreMapper;
    @Override
    public WindFileScoreEntity FDCDQYCFileScore(WindFileScoreEntity windFileScoreEntity) {

        String plantId = windFileScoreEntity.getPlantId();
        //今天00:00
        Date endDate = windFileScoreEntity.getDateTime();
        Date startDate = DateUtil.getYesterdayTime(endDate);
        String fileType = "CDQYC";
        String plantType = "FD";
        String tableName = "HISDB.NW_NE_FILE_DATACHECK_FD_CDQYC";

        //上送文件数量
        int CDQYCNumber = fileScoreMapper.selectFileNumData(tableName,plantId, fileType, plantType, startDate, endDate);
        //文件满分
        float CDQYCFullScore = fileScoreMapper.selectFileFullScore(fileType, plantType);
        //完整率
        float CDQYCRate = 0;
        //文件上送率
        float CDQYCSendRate = 0;
        //文件得分
        float CDQYCScore = 0;
        //文件合格率
        float CDQYCQualifiedRate = 0;


        if (CDQYCNumber > 0) {
            //文件上送率
            CDQYCSendRate = 100;

            CDQYCRate = (float) CDQYCNumber / 96 * 100;
            //文件数据项总得分
            float fileDataScore = fileScoreService.getFileDataScore(plantId, fileType, plantType, startDate, endDate,tableName);

            //文件得分
            CDQYCScore = fileDataScore;
            //文件合格率
            CDQYCQualifiedRate = CDQYCScore / CDQYCFullScore * 100;

        }else {
            CDQYCRate=0;
            CDQYCScore=0;
            CDQYCSendRate=0;
            CDQYCQualifiedRate= 0;
        }
        windFileScoreEntity.setCDQYCNum(CDQYCNumber);
        windFileScoreEntity.setCDQYCRate(CDQYCRate);
        windFileScoreEntity.setCDQYCScore(CDQYCScore);
        windFileScoreEntity.setCDQYCFullScore(CDQYCFullScore);
        windFileScoreEntity.setCDQYCSendRate(CDQYCSendRate);
        windFileScoreEntity.setCDQYCQualifiedRate(CDQYCQualifiedRate);

        return windFileScoreEntity;
    }

    @Override
    public PvFileScoreEntity GFCDQYCFileScore(PvFileScoreEntity pvFileScoreEntity) {
        String plantId = pvFileScoreEntity.getPlantId();
        //今天00:00
        Date endDate = pvFileScoreEntity.getDateTime();
        Date startDate = DateUtil.getYesterdayTime(endDate);
        String fileType = "CDQYC";
        String plantType = "GF";
        String tableName="HISDB.NW_NE_FILE_DATACHECK_GF_CDQYC";

        //上送文件数量
        int CDQYCNum = fileScoreMapper.selectFileNumData(tableName,plantId, fileType, plantType, startDate, endDate);
        //文件满分
        float CDQYCFullScore = fileScoreMapper.selectFileFullScore(fileType, plantType);
        //完整率
        float CDQYCRate = 0;
        //文件上送率
        float CDQYCSendRate = 0;
        //文件得分
        float CDQYCScore = 0;
        //文件合格率
        float CDQYCQualifiedRate = 0;

        if (CDQYCNum > 0) {
            //文件上送率
            CDQYCSendRate = 100;
            CDQYCRate = (float) CDQYCNum / 96 * 100;
            //文件数据项总得分
            float fileDataScore = fileScoreService.getFileDataScore(plantId, fileType, plantType, startDate, endDate,tableName);
            //文件得分
            CDQYCScore = fileDataScore;
            //文件合格率
            CDQYCQualifiedRate = CDQYCScore / CDQYCFullScore * 100;
        }else {
            CDQYCRate=0;
            CDQYCScore=0;
            CDQYCSendRate=0;
            CDQYCQualifiedRate= 0;
        }
        pvFileScoreEntity.setCDQYCNum(CDQYCNum);
        pvFileScoreEntity.setCDQYCRate(CDQYCRate);
        pvFileScoreEntity.setCDQYCScore(CDQYCScore);
        pvFileScoreEntity.setCDQYCFullScore(CDQYCFullScore);
        pvFileScoreEntity.setCDQYCQualifiedRate(CDQYCSendRate);
        pvFileScoreEntity.setCDQYCSendRate(CDQYCQualifiedRate);

        return pvFileScoreEntity;
    }

}
